# Saving Space by Taking Care of FLAC Files

Assuming all lossless audio is already encoded in [FLAC](https://xiph.org/flac/download.html) with the highest compression level, the following often overlooked procedures can be applied to save some additional space:

!!! tip
	The procedures in this guide can be automatically applied using the following Python script: [enchires.py](/assets/doc/enchires.py)

## 1. Remove embedded images

!!! warning
	* Will decrease compatibility with some hardware players.

Often images (covers, scans, etc) for an album are identical for all tracks and will be duplicated if stored embedded, therefore taking more space for no content gained.


Removing low quality embedded covers from tracks can free up enough space for a high quality separate cover without the overall size increasing by too much compared to when the covers were embedded.

=== "Recommended"
	```
	metaflac --remove --block-type=PICTURE $path
	```

## 2. Remove excess padding

!!! warning
	* May increase tagging time when embedding images.

Padding is used to make editing metadata faster. It is added to the beginning of the file, after the existing metadata and before the audio data. When metadata changes the padding will be overwritten instead of the file being lengthened and rewritten.[^1]

Some metadata editors replace removed embedded images with padding instead of shortening the file. This can leave megabytes of unused padding, which likely won't ever be used unless embedding other images later.

The recommended amount of padding is 8KiB, which is enough for editing vorbis comments.[^2]

=== "Recommended"
	```
	metaflac --dont-use-padding --remove --block-type=PADDING $path
	metaflac --add-padding=8192 $path
	```

## 3. Reencode hires with FFmpeg

!!! warning
	* Will decrease compatibility with some hardware players.

Reencoding hires audio (effectively >=88kHz) from libFLAC compression level 8 to FFmpeg compression level 11.

The FFmpeg encoder is better optimized for compressing hires audio than the official libFLAC encoder, therefore achieving higher compression rates at faster speeds. Its main feature being that it can compress silence, which is often found in high frequencies of hires audio.

* Compression level 11 is recommended for the best balance of compression ratio and speed.
* Compression level 12, although much slower, is advised when dealing with a massive library and plentiful CPU cores.
* Reencoding <88kHz hires audio is advised when saving space is of the utmost importance.

=== "Recommended"
	```
	ffmpeg -i $in -compression_level 11 $out
	```
=== "Not Advised"
	Slower and slightly worse than FFmpeg but better than using libFLAC with only maximum compression for this use case.
	```
	flac -V -8 -e -f $path
	```


{{ pageinfo(authors="Salty", created="2021/10/02", updated="2021/10/03") }}

[^1]: <https://xiph.org/flac/format.html#def_PADDING>
[^2]: <https://xiph.org/flac/documentation_tools_flac.html#flac_options_padding>
